package vshevchuk;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class masTest  
{
	
	private XList a = null;

	@Before
	public void setUp() throws Exception 
	{
		a = new AList();
	}

	@After
	public void tearDown() throws Exception 
	{
	
	}
	
	@Test 
	public void TestConstructorDefault() 
	{
		AList b = new AList();
		assertEquals(0, b.size());
	}
	
	@Test 
	public void TestConstructorSize() 
	{
		AList b = new AList(5);
		assertEquals(0, b.size());
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void TestConstructorSizeNull()
	{
		AList b = new AList(0);
	}
	
	@Test 
	public void TestConstructorArray() 
	{
		int c[]={1,2,4};
		AList b = new AList(c);
		assertEquals(3, b.size());
		assertArrayEquals(c, b.toArray());
	}
	
	@Test 
	public void TestConstructorClone()
	{
		int c[]={1,7,4,5};
		AList b = new AList(c);
		AList d = new AList(b);
		assertEquals(4, d.size());
		assertArrayEquals(c, d.toArray());
	}
	
	
	@Test 
	public void TestClone()
	{
		int c[]={1,4,4};
		AList b = new AList(c);
		AList d = b.clone();
		assertEquals(3, d.size());
		assertArrayEquals(c, d.toArray());
	}
	

	@Test 
	public void testSizeNull() 
	{
		assertEquals(0, a.size());	
	}
	
	@Test 
	public void testSize() 
	{
		int b[]={1,2,4};
		a.init(b);
		assertEquals(3, a.size());	
	}
	
	@Test
	public void testInit() 
	{	
		int b[]={1,2};
		a.init(b);
		assertEquals(2, a.size());
	}
	
	@Test
	public void testInitArray() 
	{	
		int b[]={1,2,6,8,9};
		a.init(b);
		assertEquals(5, a.size());
		assertArrayEquals(b,a.toArray());
	}
	
	@Test
	public void testGetArray() 
	{	
		int b[]={1,2,6,8,9};
		a.init(b);
		int c[]=a.toArray();
		assertEquals(5, c.length);
		assertArrayEquals(b,c);
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testGetNull()
	{	
		assertEquals(0, a.get(0));
	}
	
	@Test
	public void testGetAdd()
	{	
		a.addEnd(5);
		assertEquals(1, a.size());
		assertEquals(5, a.get(0));
	}
		
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testGetFull() 
	{	
		int b[]={1,2,6,8,9};
		a.init(b);
		assertEquals(0, a.get(5));
	}
	
	@Test 
	public void testGet()
	{	
		int b[]={1,2,6,8,9};
		a.init(b);
		assertEquals(8, a.get(3));
	}
	
	@Test
	public void testSet() 
	{
		int b[]={4,8,4};
		int c[]={3,8,4};
		a.init(b);
		a.set(3, 0);
		assertArrayEquals(c, a.toArray());	
	}

	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testSetNull() 
	{
		a.set(3, 0);
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testSetOutSize() 
	{
		a.set(3, -1);
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testSetOutSizeFull() 
	{
		int b[]={4,8,4};
		a.init(b);
		a.set(3, 3);
	}
	
	
	@Test
	public void testResize() 
	{
		AList b = new AList(3);
		int[] c={5,5,1,5};
		assertEquals(0, b.size());
		b.addEnd(5);
		b.addEnd(5);
		assertEquals(2, b.size());
		b.addEnd(1);
		b.addEnd(5);
		assertEquals(4, b.size());
		assertArrayEquals(c, b.toArray());
	}

	@Test
	public void testAddEnd() 
	{
		int b[]={5,7,8};
		int c[]={5,7,8,5};
		a.init(b);
		a.addEnd(5);
		assertArrayEquals(c, a.toArray());
	}
	
	@Test
	public void testAddEndNull() {
		a.addEnd(5);
		assertEquals(1, a.size());
		assertEquals(5, a.get(0));
	}

	@Test
	public void testAddStart() 
	{
		int b[]={5,7,8};
		int c[]={6,5,7,8};
		a.init(b);
		a.addStart(6);
		assertArrayEquals(c, a.toArray());
	}
	
	@Test
	public void testAddStartNull()
	{
		a.addStart(3);
		assertEquals(3, a.get(0));
	}

	@Test
	public void testDelEnd() 
	{
		int b[]={5,7,8};
		int c[]={5,7};
		a.init(b);
		a.delEnd();
		assertEquals(2, a.size());
		assertArrayEquals(c, a.toArray());
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testDelEndNull() 
	{
		a.delEnd();
	}

	@Test
	public void testDelStart() 
	{
		int b[]={5,7,8};
		int c[]={7,8};
		a.init(b);
		a.delStart();
		assertEquals(2, a.size());
		assertArrayEquals(c, a.toArray());
	}
	
	@Test (expected = ArrayIndexOutOfBoundsException.class)
	public void testDelStartOutSize()
	{
		a.delStart();
	}
	
	@Test 
	public void testBubbleSort() 
	{
		int b[]={5,7,8,8,2};
		int c[]={2,5,7,8,8};
		a.init(b);
		a.BubbleSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testSelectionSort() 
	{
		int b[]={5,7,8,8,2};
		int c[]={2,5,7,8,8};
		a.init(b);
		a.SelectionSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testInsertSort() 
	{
		int b[]={5,7,8,8,2};
		int c[]={2,5,7,8,8};
		a.init(b);
		a.InsertSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testQuickSort() 
	{
		int b[]={5,7,8,8,2,5,9,1,11,45};
		int c[]={1,2,5,5,7,8,8,9,11,45};
		a.init(b);
		a.QuickSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testMergeSort() 
	{
		int b[]={5,7,8,8,2,5,9,1,11,45};
		int c[]={1,2,5,5,7,8,8,9,11,45};
		a.init(b);
		a.MergeSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testShellSort() 
	{
		int b[]={5,7,8,8,2,5,9,1,11,45};
		int c[]={1,2,5,5,7,8,8,9,11,45};
		a.init(b);
		a.ShellSort();
		assertArrayEquals(c,a.toArray());	
	}
	
	@Test 
	public void testPyramidSort() 
	{
		int b[]={5,7,8,8,2,5,9,1,11,45};
		int c[]={1,2,5,5,7,8,8,9,11,45};
		a.init(b);
		a.PyramidSort();
		assertArrayEquals(c,a.toArray());
		AList x = new AList(5);
		x.print();
	}
	
}
